var imovel = arguments[0];

function adicionar(event) {
	
	imovel.detalhe = $.textArea.value;
	imovel.utilizador = Ti.App.Properties.getObject('autenticado', null).utilizador;

	var xhr = Ti.Network.createHTTPClient({
		onload : function() {
			console.log('ENTREI');
			var obj = JSON.parse(this.responseText);
			
			closeWindow();
		},
		onerror : function(e) {
			Ti.API.debug(e.error);
			alert('error');
		},
		timeout : 100000 // in milliseconds
	});
	xhr.open('POST', ip + "/server/rest/imovel/inserirImovel");
	xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
	//Define o encoding.
	xhr.send(JSON.stringify(imovel));
}

function closeWindow() {
	Alloy.Globals.adicionarImovelLocalizacao.close();
	$.adicionarImovelDetalhe.close();
}